package com.ekalenchuk.module;

import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ekalenchuk.module.constants.PageConstants;
import com.ekalenchuk.module.controllers.BaseController;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController extends BaseController {

	private static final long serialVersionUID = 6502833886237839071L;

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
//	@Autowired
//	private ArticleService articleService;
	
//	private SocialAppSettings fbAppSettings = SocialAppSettingsFacebookImpl.getApplicationSettings();
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Locale locale, Model model) {
		return PageConstants.START_REDIRECT;
	}
	
	@RequestMapping(value="/start")
	public String hello(final Model model) {
		model.addAttribute("loggedIn", isLoggedIn());
		if(isLoggedIn()) {
			model.addAttribute("firstName", getUserSession().getFirstName());
			model.addAttribute("lastName", getUserSession().getLastName());
			model.addAttribute("facebookId", getUserSession().getFacebookId());
		}
		
		return PageConstants.START;
	}

	@RequestMapping(value="/logout-success")
	public String logout() {
		logger.info("------ call logout ------");
		getUserSession().destroy();
		return PageConstants.START_REDIRECT;
	}
	
	@RequestMapping(value="/admin/start")
	public String admin() {
		return "admin-start";
	}
	
	@RequestMapping(value="/template/design")
	public String design() {
		return "design-page";
	}
}
